package com.controller;

import com.service.FloorService;
import com.service.RoomService;
import com.service.RoomTypeService;
import com.vo.RoomVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author mornd
 * @date 2020/11/30 - 15:28
 */
@Controller
@RequestMapping("/room")
public class RoomController {
    @Autowired
    private RoomService roomService;
    @Autowired
    private RoomTypeService roomTypeService;
    @Autowired
    private FloorService floorService;

    /**
     * 根据room的id查询room信息
     *
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("/detail/findById/{id}")
    public String findRoomById(@PathVariable("id") Integer id, Model model) {
        model.addAttribute("room", roomService.findRoomAndRoomTypeAndFloorById(id));
        return "detail";
    }

    /**
     * 加载房间列表
     *
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String findRoomList(Model model) {
        //加载所有房型
        model.addAttribute("roomTypeList", roomTypeService.findRoomTypeList(null));
        model.addAttribute("floorList", floorService.findFloorList(null));
        RoomVo roomVo = new RoomVo();
        //只有状态为1可预订的房间才会被查出来
        roomVo.setStatus(1);
        model.addAttribute("roomList", roomService.findRoomList(roomVo));
        return "roomList";
    }

    @RequestMapping("/findByTypeId/{id}")
    public String findRoomListByTypeId(@PathVariable("id") Integer roomTypeId, Model model) {
        //加载所有房型
        model.addAttribute("roomTypeList", roomTypeService.findRoomTypeList(null));
        model.addAttribute("floorList", floorService.findFloorList(null));
        RoomVo roomVo = new RoomVo();
        //只有状态为1可预订的房间才会被查出来
        roomVo.setStatus(1);
        //根据房间类型查询
        roomVo.setRoomTypeId(roomTypeId);
        model.addAttribute("roomList", roomService.findRoomList(roomVo));
        model.addAttribute("typeId", roomTypeId);
        return "roomList";
    }
}
